<?php
namespace web\lib;

require_once "Medoo.php";
use Medoo\Medoo;

class Login
{
    private $db;

    public function __construct(Medoo $db)
    {
        $this->db = $db;
    }

    public function signIn($userName, $password)
    {
        if ($this->db->has('users', ['username' => $userName])) {
            return [
                'code' => 1,
                'msg'  => "用户已经存在",
            ];
        } else {
            $this->db->insert('users', [
                'username' => $userName,
                'password' => $password,
            ]);

            return [
                'code' => 0,
                'msg'  => "录入成功",
            ];
        }
    }
}
